<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - import
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="ref.html">Reference</a>
            <b>></b>
          <a href="ref_directives.html">Directive Reference</a>
            <b>></b>
          import
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alphabetical Index</a>, <a href="gloss.html">Glossary</a>, <a href="ref.html">Reference</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">Java API</a>, <a href="../index.html">FreeMarker Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="ref_directive_noparse.html"><span class="hideA">Next page: </span>noparse</a></div><div class="pagerButton"><a href="ref_directive_include.html">Previous page</a></div><div class="pagerButton"><a href="ref_directives.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="ref_directive_import"></a>import  </h1>
    
    <div class="toc">
      <p>
        <b>
            Page Contents
        </b>
      </p>
      
  <ul class="noMargin">
      <li>
        <a href="#autoid_86">Synopsis</a>
      </li>
      <li>
        <a href="#autoid_87">Description</a>
      </li>
  </ul>
    </div>
    <a name="docgen_afterTheTOC"></a>
    
<a name="ref.directive.import"></a>
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_86"></a>Synopsis  </h2>


          <pre class="metaTemplate">
<tt style="color: #A03D10">&lt;#import <i style="color: #DD4400">path</i> as <i style="color: #DD4400">hash</i>&gt;</tt>
</pre>


          <p>Where:</p>

              <div class="itemizedlist">
<ul>
            <li>
              <tt style="color: #A03D10"><i style="color: #DD4400">path</i></tt>: The
              path of a template. This is an expression that evaluates to a
              string. (With other words, it doesn't have to be a fixed string,
              it can also be something like, for example,
              <tt style="color: #A03D10">profile.baseDir + &quot;/menu.ftl&quot;</tt>.)
            </li>

            <li>
              <tt style="color: #A03D10"><i style="color: #DD4400">hash</i></tt>: The
              unquoted name of hash variable by which you can access the
              namespace. Not an expression.
            </li>
          </ul>    </div>

        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_87"></a>Description  </h2>


          <p>Imports a library. That is, it creates a new empty namespace,
          and then executes the template given with
          <tt style="color: #A03D10"><i style="color: #DD4400">path</i></tt> parameter in that
          namespace so the template populates the namespace with variables
          (macros, functions, ...etc.). Then it makes the newly created
          namespace available to the caller with a hash variable. The hash
          variable will be created as a plain variable in the namespace used
          by the caller of <tt style="color: #A03D10">import</tt> (as if you would create
          it with <tt style="color: #A03D10">assign</tt> directive), with the name given
          with the <tt style="color: #A03D10"><i style="color: #DD4400">hash</i></tt>
          parameter.</p>

          <p>If you call <tt style="color: #A03D10">import</tt> with the same
          <tt style="color: #A03D10"><i style="color: #DD4400">path</i></tt> for multiple
          times, it will create the namespace and run the template for the
          very first call of <tt style="color: #A03D10">import</tt> only. The later calls
          will just create a hash by which you can access the
          <i>same</i> namespace.</p>

          <p>The output printed by the imported template will be ignored
          (will not be inserted at the place of importing). The template is
          executed to populate the namespace with variables, and not to write
          to the output.</p>

          <p>Example:</p>

          <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#import &quot;/libs/mylib.ftl&quot; as my&gt;

&lt;@my.copyright date=&quot;1999-2002&quot;/&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


          <p>The <tt style="color: #A03D10"><i style="color: #DD4400">path</i></tt>
          parameter can be a relative path like <tt style="color: #A03D10">&quot;foo.ftl&quot;</tt>
          and <tt style="color: #A03D10">&quot;../foo.ftl&quot;</tt>, or an absolute like
          <tt style="color: #A03D10">&quot;/foo.ftl&quot;</tt>. Relative paths are relative to the
          directory of the template that uses the <tt style="color: #A03D10">import</tt>
          directive. Absolute paths are relative to a base (often referred as
          the ''root directory of the templates'') that the programmer defines
          when he configures FreeMarker.</p>

          <p>Always use <tt style="color: #A03D10">/</tt> (slash) to separate path
          components, never <tt style="color: #A03D10">\</tt> (backslash). If you are
          loading templates from your local file system and it uses
          backslashes (like under. Windows), FreeMarker will convert them
          automatically.</p>

          <p>Like with the <tt style="color: #A03D10">include</tt> directive, <a href="ref_directive_include.html#ref_directive_include_acquisition">acquisition</a> and
          <a href="ref_directive_include.html#ref_directive_include_localized">localized
          lookup</a> may be used for resolving the path.</p>

          <p><span style="color:#333399; font-style:italic">Note, that it is possible to
          automatically do the commonly used imports for all templates, with
          the &quot;auto imports&quot; setting of
          <tt style="color: #A03D10">Configuration</tt>.</span></p>

          <p>If you are new to namespaces, you should read: <a href="dgui_misc_namespace.html">Template Author's Guide/Miscellaneous/Namespaces</a></p>
          
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="ref_directive_noparse.html"><span class="hideA">Next page: </span>noparse</a></div><div class="pagerButton"><a href="ref_directive_include.html">Previous page</a></div><div class="pagerButton"><a href="ref_directives.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="ref.html">Reference</a>
            <b>></b>
          <a href="ref_directives.html">Directive Reference</a>
            <b>></b>
          import
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.16
            <br>
          HTML generated: 2009-12-08 08:38:54 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

